<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
	    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
      <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body class="easyui-layout">
       <div class="easyui-container-fluid">
          <div class="easyui-pannel" style="width:100%;border: none;">
            <div class="nav"></div> 
            <div class="condition">
                <div class="condition-line">
                  <label class="column-label">渠道：</label>
                  <select id="channel" name="channelCode">
                  </select>
                  <input type="button" class="btn-search" value="查询" />
                </div>
            </div>
            <div class="table-wrapper">
             <table id="datagrid" class="easyui-datagrid">
               <thead>
                 <tr>
                   <th data-options="field:'username',align:'center'">渠道码</th>
                   <th data-options="field:'department'">模版名</th>
                   <th data-options="field:'lastlogintime'">第三列</th>
                   <th data-options="field:'entityStatus'">状态</th>
                   <th data-options="field:'action',formatter:editDelete">操作</th>
                 </tr>
               </thead>
               <tbody>
               </tbody>
             </table>
           </div>
          </div> 
       </div>  
    </body>
    <script type="text/javascript">
           $(function(){
               $("#datagrid").datagrid({
                   pagination:true,
                   rownumbers:true,
                   frozenColumns:[[{field:'check',checkbox:true}]],
                   toolbar:[{
                        iconCls:'icon-add',
                        handler:function(){
                          window.parent.addTab("添加模板","/webapp/pages/channel/template/add.html");
                        }
                      },{
                        iconCls:'icon-edit',
                        handler:function(){
                          alert('edit');
                        }
                      },{
                        iconCls:'icon-remove',
                        handler:function(){
                          alert('edit');
                        }
                    }]
               });
               $.ajax({
                   url:config.url + "/template/page",
                   type:"get",
                   xhrFields:{withCredentials:true},
                   success:function(data){
                      $("#datagrid").datagrid({data:data.content}).datagrid("getPager").pagination({
                        pageList:[10,15,20,25,30,35,40,50,100],
                        displayMsg:"共"+data.totalElements+"条记录"
                      });
                   },
                   error:function(data){
                      console.log(data);
                   }
               });

               $.ajax({
                   url:config.url +"/channels/getAll",
                   type:"get",
                   xhrFields:{withCredentials:true},
                   success:function (data) {
                        var html='<option value="">--请选择--</option>';
                        $.each(data,function (i, c) {
                            html+='<option value="'+c.code+'">'+c.name+'</option>'
                        })
                        $("#channel").html(html);
                   }
               })
           });
           function editDelete(val,row,index){
              return "<a class='linkbutton' onclick='deleteOne(\""+row.id+"\")'>删除</a>"
           }
           function deleteOne(id){
              console.log(id)
           }
      </script>
</html>
